<?php

namespace App\Http\Controllers;

use App\Library\ChargeCache;
use App\Service\ConfigService;
use Illuminate\Http\Request;

class ManageController extends Controller
{
    use ChargeCache;

    /**
     * 管理页面
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     */
    public function index(Request $request)
    {
        if ($request->post()) {
            $params = $request->post();
            if ($params['key'] == "config") {
                (new ConfigService())->config($request->post());
            }
            return redirect('/');
        }
        $key = $request->get('key', 'config');
        $start_charge = $request->get('start_charge', 2);
        $stop_charge = $request->get('stop_charge', 2);
        $query_start_charge = $request->get('query_start_charge', 2);
        $query_stop_charge = $request->get('query_stop_charge', 2);
        $notification_charge_order = $request->get('notification_charge_order', 1);
        return view('home', [
            'key' => $key,
            'vin' => $this->getKey('vin'),
            'start_charge' => $start_charge,
            'stop_charge' => $stop_charge,
            'query_start_charge' => $query_start_charge,
            'query_stop_charge' => $query_stop_charge,
            'notification_charge_order' => $notification_charge_order
        ]);
    }
}
